﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using MarketPlace.Data;
using MarketPlace.Data.DomainModels;
using MarketPlace.Web.Models;

namespace MarketPlace.Web.Controllers
{
    public partial class AccountController : System.Web.Mvc.Controllers.BaseAccountController
    {
        //
        // GET: /Account/

        //public ActionResult RegCompany()
        //{
        //    return View();
        //}

        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult RegCompany(string userName, string password, string confirmPassword, string email, string companyName, string province, string city, string webSite, FormCollection fm)
        //{
        //    ViewData["PasswordLength"] = MembershipService.MinPasswordLength;

        //    if (userName.IsNullOrEmpty())
        //    {
        //        userName = email;
        //    }

        //    if (ValidateRegistration(userName, email, password, confirmPassword
        //        /*
        //        , question, answer
        //         */
        //        ))
        //    {
        //        // Attempt to register the user
        //        MembershipCreateStatus createStatus = MembershipCreateStatus.ProviderError;
        //        MembershipUser user = MembershipService.CreateUser(userName, password, email
        //            /*
        //            , question, answer
        //             */
        //             , out createStatus);

        //        if (createStatus == MembershipCreateStatus.Success)
        //        {
        //            int newUserId = (int)user.ProviderUserKey;

        //            //AuditOption aop = new System.Web.Data.JsonPersistable<AuditOption>(true).Data;

        //            //Roles.AddUserToRole(userName, aop.CompanyRegAudit ? RoleNames.TrialCustomer : RoleNames.Customer);

        //            Int64 industryId = 39;

        //            var industry = db.Session.Get<Industry>(industryId);

        //            Company comp = new Company()
        //            {
        //                Id = newUserId,
        //                Name = companyName,
        //                Province = province,
        //                City = city,
        //                WebSite = webSite


        //            };

        //            // if (TryUpdateModel<Company>(comp, null, new string[] { "CompanyName" }))
        //            {

        //                NHibernate.ITransaction trans = null;

        //                try
        //                {
        //                    trans = db.Session.BeginTransaction();

        //                    db.Session.Save(comp);

        //                    trans.Commit();

        //                    Roles.AddUserToRole(userName, RoleNames.Company);

        //                    FormsService.SignIn(userName, false /* createPersistentCookie */);
        //                    return RedirectToAction("Index", "Home");

        //                }
        //                catch (Exception ex)
        //                {
        //                    if (null != trans)
        //                    {
        //                        trans.Rollback();
        //                    }

        //                    log.Error("Create Company Failed", ex);

        //                    Membership.DeleteUser(userName, true);

        //                    return Message(string.Format("注册用户{0}失败：{1}", userName, ex.Message));
        //                }
        //            }

        //        }
        //        else
        //        {
        //            ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
        //        }
        //    }

        //    // If we got this far, something failed, redisplay form
        //    return View();
        //}

    }
}
